package cn.edu.suse.epilepsy.controller;

import cn.edu.suse.epilepsy.common.R;
import cn.edu.suse.epilepsy.entity.dto.DoctorAddDto;
import cn.edu.suse.epilepsy.entity.pojo.DoctorManage;
import cn.edu.suse.epilepsy.entity.pojo.Patient;
import cn.edu.suse.epilepsy.service.PatientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: QingShu
 * @Date: 2024/7/10 23:25
 */
@Controller
@ResponseBody
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private PatientService patientService;
    @GetMapping("/all")
    public R selectAllDoctor() {

        return R.success(patientService.selectAllPatient());
    }
    @GetMapping("/page")
    public R getPatientPage(@RequestParam(defaultValue = "1") int current,
                           @RequestParam(defaultValue = "12") int size) {
        Page<Patient> page = new Page<>(current, size);
        QueryWrapper<Patient> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id"); // 按照 id 从大到小排序
        IPage<Patient> result = patientService.page(page, queryWrapper);
        return R.success(result);
    }
    @PostMapping("update")
    public R updateDoctor(@RequestBody Patient patient){
        int i = patientService.updatePatient(patient);
        return R.success(i);
    }
    @PostMapping("/add")
    public R addPatient(@RequestBody Patient dto) {
        Patient patient = patientService.addPatient(dto);
        return R.success(patient);
    }
    @GetMapping("{id}")
    public R deletePatient(@PathVariable Integer id) {
        boolean b = patientService.removeById(id);
        return R.success(b);
    }
}
